<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <!--{include file='comm/comm_editor.tpl'}-->
    <!--{include file="comm/icheck.tpl"}-->
    <title>商品录入-SKU</title>
</head>

<style>
.img-left{
	float:left;
	margin-left:12px;
}

.img-delete{
	width:160px;
	height:48px;
	line-height:48px;
	text-align:center;
}

.img-thumbnail{
	width:160px;
	height:160px;
}

#specSel{
	margin-top:18px;
	width:912px;
}

.form-rewrite{
	width:420px;
}

#fitSel,#intervalTime{
	margin-top:18px;
	width:650px;
}

#fitSel table td, #intervalTime table td{
	line-height:29px;
}

</style>
<body>

<div class="container">

    <div class="comm_content" style="margin-bottom:148px;">
        	<ul role="tablist" class="nav nav-tabs">
				<li class="group_box active">
					<a href="javascript:void(0);">SKU</a>
				</li>
                <button type="button" class="btn btn-primary" style="float: right;margin:4px 15px 0px 0px;" onclick="history.go(-1)">返回上一级</button>
            </ul>
			
        	<div class="form-horizontal">
        		<!--用于判断是商品添加还是商品编辑-->
				<div class="form-group" style="width:800px;padding:10px;margin-bottom:0px;">
					<label class="col-sm-3 control-label" for="cityID" style="width:18%;"><span class="red">*</span> 商品所属城市：</label>
					<div class="col-sm-9" style="width:82%;">
						<select name="cityID" id="cityID" class="form-control w150" disabled>
							<option value="0">请选择</option>
							<!--{foreach from=$editInfo->city item=c}-->
								<option value="<!--{$c.id}-->"><!--{$c.name}--></option>
							<!--{/foreach}-->
						</select>
					</div>
				</div>
				
				<div class="form-group" style="width:800px;padding:10px;margin-bottom:0px;">
					<label class="col-sm-3 control-label" for="categoryID" style="width:18%;"><span class="red">*</span> 商品类目：</label>
					<div class="col-sm-9" style="width:82%;">
						<select name="categoryID" id="categoryID" class="form-control w150" disabled>
							<option value="0">请选择</option>
							<!--{foreach from=$editInfo->category item=c}-->
								<option value="<!--{$c.bigCategoryID}-->"><!--{$c.name}--></option>
							<!--{/foreach}-->
						</select>
					</div>
				</div>
				
				<div class="form-group" style="width:800px;padding:10px;margin-bottom:0px;">
					<label class="col-sm-3 control-label" for="goods-name" style="width:18%;"><span class="red">*</span> 商品名称：</label>
					<div class="col-sm-9" style="padding-left:0px;width:82%;">
						<div class="form-group">
							<label class="col-sm-3 control-label" for="goodsName" style="width:9%;">中文</label>
							<div class="col-sm-9" style="padding:0px;width:91%;">
								<input type="text" name="goodsName" id="goodsName" class="form-control w300" maxlength="15" disabled>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label" for="frenchName" style="width:9%;">法文</label>
							<div class="col-sm-9" style="padding:0px;width:91%;">
								<input type="text" name="frenchName" id="frenchName" class="form-control w300" maxlength="30" disabled>
							</div>
						</div>
					</div>
				</div>
				
				<div class="form-group" style="padding:10px;margin-bottom:0px;">
					<label class="col-sm-3 control-label" for="spec" style="width:11.5%;"><span class="red">*</span> 商品规格：</label>
					<div class="col-sm-9" style="width:88.5%;">
						<div>
							<span style="display:inline-block;height:96px;vertical-align:middle;">规格组：</span>
							<select name="specGroupID" id="specGroupID" class="form-control w150" onchange="goodsAdd.changeSpec();" style="display:inline-block;margin-bottom:75px;">
								<!--{foreach from=$editInfo->specGroup item=g}-->
									<option value="<!--{$g.specGroupID}-->"><!--{$g.specGroupName}--></option>
								<!--{/foreach}-->
							</select>
							<span style="display:inline-block;height:96px;vertical-align:middle;margin-left:32px;">规格：</span>
							<select name="specID" id="specID" class="form-control w150" disabled multiple style="display:inline-block;height:110px;">
								<!--{foreach from=$editInfo->goodsSpec item=s}-->
									<option value="<!--{$s.specID}-->"><!--{$s.specName}--></option>
								<!--{/foreach}-->
							</select>
						</div>
						<div id="specSel">
							<table class="table table-bordered table-hover">
								<thead>
									<tr>
										<!--<th width="10%" style="text-align:left;padding-left:36px;">操作</th>-->
										<th width="10%" style="text-align:center;">规格</th>
										<th width="12%" style="text-align:center;">SKU编号</th>
										<th width="12%" style="text-align:center;">售价</th>
										<th width="22%" style="text-align:center;">提前预定时间</th>
										<th width="10%" style="text-align:center;">网站状态</th>
										<th width="12%" style="text-align:center;">销售状态</th>
										<th width="12%" style="text-align:center;">试吃状态</th>
									</tr>
								</thead>
								<tbody>
									<!--{if isset($editInfo->saleGoods) && $editInfo->saleGoods != ''}-->
										<!--{foreach from=$editInfo->saleGoods item=sale}-->
											<tr id="tr_<!--{$sale.specGroupID}-->_<!--{$sale.specID}-->">
												<!--<td id="operate_<!--{$sale.specGroupID}-->_<!--{$sale.specID}-->" style="text-align:center;">
													<a onclick="goodsAdd.editSku('<!--{$sale.specGroupID}-->', '<!--{$sale.specID}-->');" href="javascript:void(0);">编辑</a>
													<input type="hidden" name="tPostID_<!--{$sale.specGroupID}-->_<!--{$sale.specID}-->" id="tPostID_<!--{$sale.specGroupID}-->_<!--{$sale.specID}-->" value="<!--{$sale.postID}-->">
												</td>-->
												<td style="text-align:center;" id="sName_<!--{$sale.specGroupID}-->_<!--{$sale.specID}-->"><!--{$sale.specName}--></td>
												<td id="sku_<!--{$sale.specGroupID}-->_<!--{$sale.specID}-->"><!--{$sale.product_code}--></td>
												<td style="text-align:center;" id="salePrice_<!--{$sale.specGroupID}-->_<!--{$sale.specID}-->"><!--{$sale.salePrice}--></td>
												<td style="text-align:center;" id="schedule_<!--{$sale.specGroupID}-->_<!--{$sale.specID}-->"><!--{$sale.aheadTime}--></td>
												<td style="text-align:center;" id="useFlg_<!--{$sale.specGroupID}-->_<!--{$sale.specID}-->">
													<!--{if $sale.useFlg == 1}-->
														上架
													<!--{elseif $sale.useFlg == 0}-->
														下架
													<!--{else}-->	
														售罄
													<!--{/if}-->	
												</td>
												<td style="text-align:center;" id="forsale_<!--{$sale.specGroupID}-->_<!--{$sale.specID}-->">
													<!--{if $sale.forsale == 1}-->
														可销售
													<!--{else}-->
														不可销售
													<!--{/if}-->	
												</td>
												<td style="text-align:center;" id="foretaste_<!--{$sale.specGroupID}-->_<!--{$sale.specID}-->">
													<!--{if $sale.foretaste == 1}-->
														可试吃
													<!--{else}-->
														不可试吃
													<!--{/if}-->	
												</td>
											</tr>
										<!--{/foreach}-->
									<!--{/if}-->
								</tbody>
							</table>
						</div>
					</div>
				</div>
	        </div>   
        </div>
    
</div>

<div id="pop" style="display: none;">

    <form class="form-horizontal" id="addForm" name="addForm" onsubmit="return false;" style="margin-bottom:80px;">
    
    	<div class="form-group" style="width:909px;">
			<label class="col-sm-3 control-label" for="setMainGoods" style="width:23%;">设为主商品：</label>
			<div class="col-sm-9" style="width:77%;padding-top:6px;">
				<input type="hidden" name="postID" id="postID" value="<!--{$editInfo->postID}-->">	<!--二级网购号-->
				<input type="hidden" name="tPostID" id="tPostID" value=""> <!--三级网购号-->
				<input type="hidden" name="hSpecGroupID" id="hSpecGroupID" value=""> <!--规格组ID-->
				<input type="hidden" name="hSpecID" id="hSpecID" value=""> <!--规格ID-->
				<div class="fl">
					<input type="radio" value="1" name="setMainGoods" id="setMainGoods_1" class="square-radio">
					<label for="setMainGoods_0">是</label>
				</div>
				<div class="fl" style="margin-left:22px;">
					<input type="radio" value="0" name="setMainGoods" id="setMainGoods_0" class="square-radio">
					<label for="setMainGoods_1">否</label>
				</div>
			</div>
		</div>
    
	    <div>
	        <div class="form-group form-rewrite" style="float:left;">
	            <label for="product_code" class="col-sm-3 control-label" style="width:50%;"><span class="red">*</span> SKU：</label>
	            <div class="col-sm-9" style="width:50%;">
	                <input type="text" class="form-control w150" id="product_code" name="product_code" maxlength="100" />
	            </div>
	        </div>
	        
	        <div class="form-group form-rewrite" style="float:left;">
	            <label for="salePrice" class="col-sm-3 control-label" style="width:50%;"><span class="red">*</span> 售价：</label>
	            <div class="col-sm-9" style="width:50%;">
	                <input type="text" class="form-control w150" id="salePrice" name="salePrice" maxlength="10" />
	            </div>
	        </div>
	        <div style="clear:both;"></div>
		</div>        
        
		<div>
			<div class="form-group form-rewrite" style="float:left;">
				<label class="col-sm-3 control-label" for="aheadTime" style="width:50%;"><span class="red">*</span> 提前预定时间：</label>
				<div class="col-sm-9" style="width:50%;">
					<select name="aheadTime" id="aheadTime" class="form-control w150">
						<option value="0">请选择</option>
						<!--{foreach from=$editInfo->aheadTime_array item=ahead}-->
		                    <option value="<!--{$ahead.itemID}-->"><!--{$ahead.itemName}--></option>
		                <!--{/foreach}-->
					</select>
				</div>
			</div>
			
			<div class="form-group form-rewrite" style="float:left;">
				<label class="col-sm-3 control-label" for="edible" style="width:50%;">食用：</label>
				<div class="col-sm-9" style="width:50%;">
					<select name="edible" id="edible" class="form-control w150">
						<option value="0">请选择</option>
						<!--{foreach from=$editInfo->edible_array item=edible}-->
		                    <option value="<!--{$edible.itemID}-->"><!--{$edible.itemName}--></option>
		                <!--{/foreach}-->
					</select>
				</div>
			</div>
			<div style="clear:both;"></div>
		</div>
		
		<div>
			<div class="form-group form-rewrite" style="float:left;">
				<label class="col-sm-3 control-label" for="size" style="width:50%;">尺寸：</label>
				<div class="col-sm-9" style="width:50%;">
					<select name="size" id="size" class="form-control w150">
						<option value="0">请选择</option>
						<!--{foreach from=$editInfo->size_array item=size}-->
		                    <option value="<!--{$size.itemID}-->"><!--{$size.itemName}--></option>
		                <!--{/foreach}-->
					</select>
				</div>
			</div>
			
			<div class="form-group form-rewrite" style="float:left;">
				<label class="col-sm-3 control-label" for="useFlg" style="width:50%;"><span class="red">*</span> 网站状态：</label>
				<div class="col-sm-9" style="width:50%;">
					<select name="useFlg" id="useFlg" class="form-control w150">
						<option value="0">请选择</option>
						<option value="1">上架</option>
						<option value="2">下架</option>
						<option value="3">售罄</option>
					</select>
				</div>
			</div>
			<div style="clear:both;"></div>
		</div>
		
		<div>
			<div class="form-group form-rewrite" style="float:left;" >
				<label class="col-sm-3 control-label" for="forsale" style="width:50%;"><span class="red">*</span> 销售状态：</label>
				<div class="col-sm-9" style="width:50%;">
					<select name="forsale" id="forsale" class="form-control w150">
						<option value="0">请选择</option>
						<option value="1">可销售</option>
						<option value="2">不可销售</option>
					</select>
				</div>
			</div>
			
			<div class="form-group form-rewrite" style="float:left;">
				<label class="col-sm-3 control-label" for="foretaste" style="width:50%;"><span class="red">*</span> 试吃状态：</label>
				<div class="col-sm-9" style="width:50%;">
					<select name="foretaste" id="foretaste" class="form-control w150">
						<option value="0">请选择</option>
						<option value="1">可试吃</option>
						<option value="2">不可试吃</option>
					</select>
				</div>
			</div>
			<div style="clear:both;"></div>
		</div>

		<div class="form-group" style="width:909px;">
			<label class="col-sm-3 control-label" for="syncopate" style="width:23%;">切分：</label>
			<div class="col-sm-9" style="width:77%;">
				<div>
					<select name="syncopate" id="syncopate" class="form-control w150" multiple style="height:110px;display:inline-block;">
						<!--{foreach from=$editInfo->syncopate_array item=syncopate}-->
		                    <option value="<!--{$syncopate.itemID}-->"><!--{$syncopate.itemName}--></option>
		                <!--{/foreach}-->
					</select>
					<div style="height:110px;display:inline-block;margin-left:113px;vertical-align:middle;margin-top:18px;">
						<button class="btn btn-default" onclick="goodsAdd.moveLeft(1);" type="button"> > </button>
						<button class="btn btn-default" onclick="goodsAdd.moveRight(1);" type="button" style="margin-top:19px;display:block;"> < </button>
					</div>
					<select name="selSyncopate" id="selSyncopate" class="form-control w150" multiple style="height:110px;display:inline-block;margin-left:113px;"></select>
				</div>
			</div>
		</div>
		
		<div class="form-group" style="width:909px;">
			<label class="col-sm-3 control-label" for="birthcard" style="width:23%;">生日牌：</label>
			<div class="col-sm-9" style="width:77%;">
				<div>
					<select name="birthcard" id="birthcard" class="form-control w150" multiple style="height:110px;display:inline-block;">
						<!--{foreach from=$editInfo->birthcard_array item=birthcard}-->
		                    <option value="<!--{$birthcard.itemID}-->"><!--{$birthcard.itemName}--></option>
		                <!--{/foreach}-->
					</select>
					<div style="height:110px;display:inline-block;margin-left:113px;vertical-align:middle;margin-top:18px;">
						<button class="btn btn-default" onclick="goodsAdd.moveLeft(2);" type="button"> > </button>
						<button class="btn btn-default" onclick="goodsAdd.moveRight(2);" type="button" style="margin-top:19px;display:block;"> < </button>
					</div>
					<select name="selBirthcard" id="selBirthcard" class="form-control w150" multiple style="height:110px;display:inline-block;margin-left:113px;"></select>
				</div>
			</div>
		</div>
		
		<div class="form-group" style="width:909px;">
			<label class="col-sm-3 control-label" for="fitID" style="width:23%;">配件：</label>
			<div class="col-sm-9" style="width:77%;">
				<div>
					<select name="fitID" id="fitID" class="form-control w150" multiple style="display:inline-block;height:110px;">
						<!--{foreach from=$editInfo->goodsFit item=fit}-->
		                    <option value="<!--{$fit.fitID}-->" unitName="<!--{$fit.unitName}-->"><!--{$fit.fitName}--></option>
		                <!--{/foreach}-->
					</select>
					<span style="display:inline-block;vertical-align:middle;height:110px;">
						<button class="btn btn-primary" type="button" style="display:block;margin:15px 0 15px;" onclick="goodsAdd.batchFit();">批量新增</button>
						<button class="btn btn-default" type="button" onclick="goodsAdd.openFit();">配件基础信息新增</button>
					</span>
				</div>
				<div id="fitSel">
					<table class="table table-bordered table-hover">
						<thead>
							<tr>
								<th width="12%" style="text-align:center;">操作</th>
								<th width="18%" style="text-align:center;">配件名称</th>
								<th width="12%" style="text-align:center;">单位</th>
								<th width="18%" style="text-align:center;">数量 <font color="Red">*</font></th>
								<th width="40%" style="text-align:center;">是否可销售</th>
							</tr>
						</thead>
						<tbody></tbody>
					</table>
				</div>
			</div>
		</div>
		
		<div class="form-group" style="width:909px;">
			<label class="col-sm-3 control-label" for="time" style="width:23%;"><span class="red">*</span> 配送时间控制：</label>
			<div class="col-sm-9" style="width:77%;">
				
				<div>
					<div class="form-group" style="float:left;">
						<label class="col-sm-3 control-label" for="startDeliver" style="width:45%;">起始配送时间：</label>
						<div class="col-sm-9" style="width:55%;">
							<input id="startDeliver" class="form-control w150" type="text" name="startDeliver" maxlength="100">
						</div>
					</div>
					
					<div class="form-group" style="float:left;margin-left:22px;">
						<label class="col-sm-3 control-label" for="endDeliver" style="width:45%;">结束配送时间：</label>
						<div class="col-sm-9" style="width:55%;">
							<input id="endDeliver" class="form-control w150" type="text" name="endDeliver" maxlength="100">
						</div>
					</div>
					<div style="clear:both;"></div>
				</div>
				
				<div>
					<div class="form-group" style="float:left;">
						<label class="col-sm-3 control-label" for="interval" style="width:49%;">配送间隔：</label>
						<div class="col-sm-9" style="width:51%;">
							<select name="interval" id="interval" class="form-control w150" onclick="goodsAdd.changeInter();">
								<option value="1">1</option>
								<option value="0">0</option>
							</select>
						</div>
					</div>
					
					<div class="form-group" id="cutTimeCase" style="float:left;margin-left:50px;">
						<label class="col-sm-3 control-label" for="cutTime" style="width:49%;">截单时间：</label>
						<div class="col-sm-9" style="width:51%;">
							<input id="cutTime" class="form-control w150" type="text" name="cutTime" maxlength="100">
						</div>
					</div>
					<div style="clear:both;"></div>
				</div>
				<div id="intervalTime" style="display:none;">
					<button class="btn btn-default" onclick="goodsAdd.sameOrder();" type="button">当天下单/配送时间控制</button>
					<table class="table table-bordered table-hover">
						<thead>
							<tr>	
								<th width="16%" style="text-align:center;">操作</th>
								<th width="21%" style="text-align:center;">下单开始时间</th>
								<th width="21%" style="text-align:center;">下单结束时间</th>
								<th width="21%" style="text-align:center;">最早配送开始时间</th>
								<th width="21%" style="text-align:center;">最晚配送开始时间</th>
							</tr>
						</thead>
						<tbody></tbody>
					</table>
				</div>
				
			</div>
		</div>
		
		<div class="form-group" style="width:909px;">
			<label class="col-sm-3 control-label" for="description" style="width:23%;">页面内容维护：</label>
			<div class="col-sm-9" style="width:77%;">
				<textarea name="description" id="description" style="height:270px;"></textarea>
			</div>
		</div>
    </form>

</div>

<!--{include file='comm/footer.tpl'}-->
</body>
</html>
<script>
	
	$(function(){
		//编辑初始化
		<!--{if isset($editInfo) && $editInfo != ''}-->
			$('#cityID').val('<!--{$editInfo->cityID}-->');
			$('#categoryID').val('<!--{$editInfo->bigCategoryID}-->');
			$('#goodsName').val('<!--{$editInfo->goodsName}-->');
			$('#frenchName').val('<!--{$editInfo->frenchName}-->');
			<!--{if isset($editInfo->selSpecGroupID) && $editInfo->selSpecGroupID != '' && $editInfo->selSpecGroupID != 0}-->
				$('#specGroupID').val('<!--{$editInfo->selSpecGroupID}-->').attr('disabled','true');
			<!--{/if}-->
		<!--{/if }-->
	})
    
    //商品主信息添加操作对象
	var goodsAdd = {
		
		//规格添加
		openSpec: function(){
			window.open('/quanliadmin/app/goods/goodsSpec.pscript?operFlg=1');
		},
		
		//切换规格组
		changeSpec: function(){
			var specGroupID = $('#specGroupID').val();
			E.ajax_post({
				url : '/invokingAjax-backend/goods/goodsEdit.ajax?operFlg=5',
				data: {
					specGroupID: specGroupID
				},
				call: 'goodsAdd.specCall'
			});
		},
		
		//选择规格组后回调
		specCall: function(o){
			if (o.code == 200) {
				var oStr = '';
				$.each(o.data, function(k, v){
					oStr += '<option value="'+v.specID+'">'+v.specName+'</option>';
				})
				
				$('#specID').html(oStr);
			} else {
				E.alert(o.message);
			}
		},
		
		//批量添加规格
		batchSpec: function(){
			var sLen = $('#specID option:checked').length;
			if (!E.isInt(sLen) || sLen <= 0) {
				E.alert('请选择商品规格');
				return false;
			}
			
			var specGroupID = $('#specGroupID').val();
			if (!E.isInt(specGroupID) || specGroupID <= 0) {
				E.alert('请选择商品规格组');
				return false;
			}
			
			var tStr = '';
			var error_msg = '';
			$('#specID option:checked').each(function(k, v){
				
				var isTr = $('#tr_' + specGroupID + '_' + $(this).val()).length;
				if (isTr > 0) {
					error_msg += '规格「' + $(this).text() + '」已添加';
					return false;
				}
				
				tStr += '<tr id="tr_' + specGroupID + '_'+ $(this).val() + '">';
					tStr += '<td style="text-align:center;" id=operate_' + specGroupID + '_'+ $(this).val() +'>';
						tStr += '<a href="javascript:void(0);" onclick="goodsAdd.editSku(' + specGroupID + ', ' + $(this).val() + ');">编辑</a>&nbsp;&nbsp;';
						tStr += '<a href="javascript:void(0);" onclick="goodsAdd.delLine(' + specGroupID + ', ' + $(this).val() + ');">删除</a>';
					tStr += '</td>';
					tStr += '<td id="sName_' + specGroupID + '_' + $(this).val() + '" style="text-align:center;">';
						tStr += $(this).text();
					tStr += '</td>';
					tStr += '<td id="sku_' + specGroupID + '_' + $(this).val() + '">';
						tStr += '';
					tStr += '</td>';
					tStr += '<td id="salePrice_' + specGroupID + '_' + $(this).val() + '" style="text-align:center;">';
						tStr += '';
					tStr += '</td>';
					tStr += '<td id="schedule_' + specGroupID+'_' + $(this).val() + '" style="text-align:center;">';
						tStr += '';
					tStr += '</td>';
					tStr += '<td id="useFlg_' + specGroupID + '_' + $(this).val() + '" style="text-align:center;">';
						tStr += '下架';
					tStr += '</td>';
					tStr += '<td id="forsale_' + specGroupID + '_' + $(this).val() + '" style="text-align:center;">';
						tStr += '不可销售';
					tStr += '</td>';
					tStr += '<td id="foretaste_' + specGroupID + '_' + $(this).val() + '" style="text-align:center;">';
						tStr += '不可试吃';
					tStr += '</td>';
				tStr += '</tr>';
			})
			
			if (error_msg != '') {
				E.alert(error_msg);
				return false;
			}
			
			$('#specSel table tbody').append(tStr);
			$('#specGroupID').attr('disabled', 'true');
			
		},
		
		//删除行
		delLine: function(gid, sid){

			$('#tr_' + gid + '_' + sid).remove();
			
			var sLen = $('#specSel table tbody tr').length;
			if (sLen <= 0) {
				$('#specGroupID').removeAttr('disabled', 'false');
			}
		},
		
		//编辑sku(规格)
		editSku: function(gid, sid){
			var sName = $('#sName_'  + gid + '_' + sid).text();
			E.popup.open({
                id:"pop",
                title: '编辑SKU-' + sName,
                css: "width: 990px;height:460px;margin:-10px auto;overflow:visible;",
                btnName: "保存",
                btnCall:"goodsAdd.check();"
            });
            
            //三级商品ID
			var tPostID = $('#tPostID_' + gid + '_' + sid).val();
            $('#tPostID').val(tPostID);
            $('#hSpecGroupID').val(gid);
            $('#hSpecID').val(sid);
            
			$('.square-radio').iCheck({
	            checkboxClass: 'icheckbox_square-blue',
	            radioClass: 'iradio_square-blue',
	            increaseArea: '20%'
	        });
            
	        if (tPostID) {
	        	E.loadding.open();
	        	E.ajax_post({
	        		url : '/invokingAjax-backend/goods/goodsAdd.ajax?operFlg=6',
					data: {
						postID: tPostID
					},
					call: 'goodsAdd.skuCall'
	        	});
	        } else {
	      		window.editor = KindEditor.create("#description");
	        }
		},
		
		//初始化显示sku内容
		skuCall: function(o){
			E.loadding.close();
			if (o.code == 200) {
				$('#setMainGoods_' + o.data.mainGoodsFlg).iCheck('check');
				$('#product_code').val(o.data.product_code);
				$('#salePrice').val(o.data.salePrice);
				$('#aheadTime').val(o.data.aheadTimeID);
				$('#edible').val(o.data.edibleID);
				$('#size').val(o.data.sizeID);
				$('#useFlg').val(o.data.useFlg);
				$('#forsale').val(o.data.forsale);
				$('#foretaste').val(o.data.foretaste);
				$('#startDeliver').val(o.data.startDeliver);
				$('#endDeliver').val(o.data.endDeliver);
				$('#interval').val(o.data.interval);
				$('#description').val(o.data.description);
				
				//配送间隔
				if (o.data.interval == 1) {
					$('#cutTime').val(o.data.cutTime);
					$('#intervalTime').css('display', 'none');
					$('#cutTimeCase').css('display', 'block');
				} else {
					$('#cutTimeCase').css('display', 'none');
					$('#intervalTime').css('display', 'block');
					var sameStr = '';
					$.each(o.data.space, function(k, v){
						sameStr += '<tr id=same_' + goodsAdd.sameCount + '>';
							sameStr += '<td style="text-align:center;">';
								sameStr += '<a href="javascript:void(0);" onclick="goodsAdd.sameDel(' + goodsAdd.sameCount + ');">删除</a>';
							sameStr += '</td>';
							sameStr += '<td>';
								sameStr += '<input id=sameOsTime_' + goodsAdd.sameCount + ' name=sameOsTime_' + goodsAdd.sameCount + ' class="form-control" type="text" style="width:118px;" value=' + v.startOrderTime + ' maxlength="20">';
							sameStr += '</td>';
							sameStr += '<td>';
								sameStr += '<input id=sameOeTime_' + goodsAdd.sameCount + ' name=sameOeTime_' + goodsAdd.sameCount + ' class="form-control" type="text" style="width:118px;" value=' + v.endOrderTime + ' maxlength="20">';
							sameStr += '</td>';
							sameStr += '<td>';
								sameStr += '<input id=sameDsTime_' + goodsAdd.sameCount + ' name=sameDsTime_' + goodsAdd.sameCount + ' class="form-control" type="text" style="width:118px;" value=' + v.startDeliverTime + ' maxlength="20">';
							sameStr += '</td>';
							sameStr += '<td>';
								sameStr += '<input id=sameDeTime_' + goodsAdd.sameCount + ' name=sameDeTime_' + goodsAdd.sameCount + ' class="form-control" type="text" style="width:118px;" value=' + v.endDeliverTime + ' maxlength="20">';
							sameStr += '</td>';
						sameStr += '</tr>';
						
						goodsAdd.sameCount++;
					});
					$('#intervalTime table tbody').append(sameStr);
				}

				//配件
				if (o.data.fit != '') {
					fitStr = '';
					$.each(o.data.fit, function(k, v){
						fitStr += '<tr id=fit_' + v.fitID + '>';
							fitStr += '<td style="text-align:center;">';
								fitStr += '<input type="checkbox" name="selectFit" checked value="'+ v.fitID +'" style="display:none;">';
								fitStr += '<a href="javascript:void(0);" onclick="goodsAdd.fitDel(' + v.fitID + ');">删除</a>';
							fitStr += '</td>';
							fitStr += '<td style="text-align:center;overflow:hidden;">';
								fitStr += v.fitName;
							fitStr += '</td>';
							fitStr += '<td style="text-align:center;">';
								fitStr += v.unitName;
							fitStr += '</td>';
							fitStr += '<td style="text-align:center;">';
								fitStr += '<input type="text" maxlength="10" name="fitCount_' + v.fitID + '" id="fitCount_' + v.fitID + '" class="form-control" value=' + v.quantity + ' style="width:60px;margin-left:19px;" onblur=goodsAdd.fitCountBlur(' + v.fitID + ');>';
							fitStr += '</td>';
							if (v.forsale == 1) {
								fitStr += '<td style="text-align:center;">';
									fitStr += '<div class="fl" style="margin-left:10px;">';
										fitStr += '<input type="radio" value="0" name=sale_radio_' + v.fitID + ' class="square-radio" onclick=goodsAdd.fitNoSale(' + v.fitID + ');>';
										fitStr += '<label for="sale_radio_' + v.fitID + '_0">&nbsp;不可销售</label>';
									fitStr += '</div>';
									fitStr += '<div class="fl" style="margin-left:10px;">';
										fitStr += '<input type="radio" value="1" name=sale_radio_' + v.fitID + ' checked class="square-radio" onclick=goodsAdd.fitSale(' + v.fitID + ');>';
										fitStr += '<label for="sale_radio_' + v.fitID + '_1">&nbsp;可销售</label>';
									fitStr += '</div>';
									fitStr += '<div class="fl" style="margin-left:10px;">';
										if (parseFloat(v.price) <= 0) {
											fitStr += '<input type="text" maxlength="10" name="fitPrice_' + v.fitID + '" id="fitPrice_' + v.fitID + '" class="form-control" style="width:60px;" value="售价" onfocus=goodsAdd.fitfocus(' + v.fitID + '); onblur=goodsAdd.fitblur(' + v.fitID + ');>';
										} else {
											fitStr += '<input type="text" maxlength="10" name="fitPrice_' + v.fitID + '" id="fitPrice_' + v.fitID + '" class="form-control" style="width:60px;" value=' + v.price + ' onfocus=goodsAdd.fitfocus(' + v.fitID + '); onblur=goodsAdd.fitblur(' + v.fitID + ');>';
										}
									fitStr += '</div>';
								fitStr += '</td>';
							} else {
								fitStr += '<td style="text-align:center;">';
									fitStr += '<div class="fl" style="margin-left:10px;">';
										fitStr += '<input type="radio" value="0" name=sale_radio_' + v.fitID + ' checked class="square-radio" onclick=goodsAdd.fitNoSale(' + v.fitID + ');>';
										fitStr += '<label for="sale_radio_' + v.fitID + '_0">&nbsp;不可销售</label>';
									fitStr += '</div>';
									fitStr += '<div class="fl" style="margin-left:10px;">';
										fitStr += '<input type="radio" value="1" name=sale_radio_' + v.fitID + ' class="square-radio" onclick=goodsAdd.fitSale(' + v.fitID + ');>';
										fitStr += '<label for="sale_radio_' + v.fitID + '_1">&nbsp;可销售</label>';
									fitStr += '</div>';
									fitStr += '<div class="fl" style="margin-left:10px;">';
										if (parseFloat(v.price) <= 0) {
											fitStr += '<input type="text" maxlength="10" name="fitPrice_' + v.fitID + '" id="fitPrice_' + v.fitID + '" class="form-control" style="width:60px;" value="售价" onfocus=goodsAdd.fitfocus(' + v.fitID + '); onblur=goodsAdd.fitblur(' + v.fitID + ');>';
										} else {
											fitStr += '<input type="text" maxlength="10" name="fitPrice_' + v.fitID + '" id="fitPrice_' + v.fitID + '" class="form-control" style="width:60px;" value=' + v.price + ' onfocus=goodsAdd.fitfocus(' + v.fitID + '); onblur=goodsAdd.fitblur(' + v.fitID + ');>';
										}
									fitStr += '</div>';
								fitStr += '</td>';
							}
							
							
						fitStr += '</tr>';
					});
					
					//切分
					if (o.data.sync_total != '') {
						var syncStr = '';
						$.each(o.data.sync_total, function(k, v){
							syncStr += '<option value=' + v.id + '>' + v.name + '</option>';

							$('#syncopate option:[value="'+v.id+'"]').remove();
						});
						$('#selSyncopate').append(syncStr);
					}
					
					//生日牌
					if (o.data.birth_total != '') {
						var birthStr = '';
						$.each(o.data.birth_total, function(k, v){
							birthStr += '<option value=' + v.id + '>' + v.name + '</option>';
							
							$('#birthcard option:[value="'+v.id+'"]').remove();
						});
						$('#selBirthcard').append(birthStr);
					} else {
						$('#selBirthcard').append('');
					}
					
					window.editor = KindEditor.create("#description");
					$('#fitSel table tbody').append(fitStr);
					$('.square-radio').iCheck({
			            checkboxClass: 'icheckbox_square-blue',
			            radioClass: 'iradio_square-blue',
			            increaseArea: '20%'
			        });
				}
			} else {
				E.alert(o.message);
			}
		},
		
		//左移
		moveLeft: function(flg){
			if (flg == 1) {	//切分
				var syncLen = $('#syncopate option:checked').length;
				if (syncLen <= 0) {
					E.alert('请选择切分');
					return false;
				}
				$('#syncopate option:checked').each(function(){
					$('#selSyncopate').append($(this));
				});
			} else {	//生日牌
				var birthLen = $('#birthcard option:checked').length;
				if (birthLen <= 0) {
					E.alert('请选择生日牌');
					return false;
				}
				$('#birthcard option:checked').each(function(){
					$('#selBirthcard').append($(this));
				});
			}
		},
		
		//右移
		moveRight: function(flg){
			if (flg == 1) {	//切分
				var syncLen = $('#selSyncopate option:checked').length;
				if (syncLen <= 0) {
					E.alert('请选择切分');
					return false;
				}
				$('#selSyncopate option:checked').each(function(){
					$('#syncopate').append($(this));
				});
			} else {	//生日牌
				var birthLen = $('#selBirthcard option:checked').length;
				if (birthLen <= 0) {
					E.alert('请选择生日牌');
					return false;
				}
				$('#selBirthcard option:checked').each(function(){
					$('#birthcard').append($(this));
				});
			}
		},
		
		//添加配件
		openFit: function(){
			window.open('/quanliadmin/app/goods/goodsFittings.pscript?operFlg=1');
		},
		
		//批量添加配件
		batchFit: function(){
			var fitLen = $('#fitID option:checked').length;
			if (!E.isInt(fitLen) || fitLen <= 0) {
				E.alert('请选择配件');
				return false;
			}
			
			var fitStr = '';
			var error_msg = '';
			$('#fitID option:checked').each(function(k, v){
				var selLen = $('#fit_' + $(this).val()).length;
				if (selLen > 0) {
					error_msg += '配件「' + $(this).text() + '」已选择';
					return false;
				}
				
				fitStr += '<tr id=fit_' + $(this).val() + '>';
					fitStr += '<td style="text-align:center;">';
						fitStr += '<input type="checkbox" name="selectFit" checked value="'+ $(this).val() +'" style="display:none;">';
						fitStr += '<a href="javascript:void(0);" onclick="goodsAdd.fitDel(' + $(this).val() + ');">删除</a>';
					fitStr += '</td>';
					fitStr += '<td style="text-align:center;overflow:hidden;">';
						fitStr += $(this).text();
					fitStr += '</td>';
					fitStr += '<td style="text-align:center;">';
						fitStr += $(this).attr('unitname');
					fitStr += '</td>';
					fitStr += '<td style="text-align:center;">';
						fitStr += '<input type="text" maxlength="10" name="fitCount_' + $(this).val() + '" id="fitCount_' + $(this).val() + '" class="form-control" value="1" style="width:60px;margin-left:19px;" onblur=goodsAdd.fitCountBlur(' + $(this).val() + ');>';
					fitStr += '</td>';
					fitStr += '<td style="text-align:center;">';
						fitStr += '<div class="fl" style="margin-left:10px;">';
							fitStr += '<input type="radio" value="0" name=sale_radio_' + $(this).val() + ' checked class="square-radio" onclick=goodsAdd.fitNoSale(' + $(this).val() + ');>';
                            fitStr += '<label for="sale_radio_' + $(this).val() + '_0">&nbsp;不可销售</label>';
                        fitStr += '</div>';
                        fitStr += '<div class="fl" style="margin-left:10px;">';
                        	fitStr += '<input type="radio" value="1" name=sale_radio_' + $(this).val() + ' class="square-radio" onclick=goodsAdd.fitSale(' + $(this).val() + ');>';
                            fitStr += '<label for="sale_radio_' + $(this).val() + '_1">&nbsp;可销售</label>';
                        fitStr += '</div>';
                        fitStr += '<div class="fl" style="margin-left:10px;">';
                        	fitStr += '<input type="text" maxlength="10" name="fitPrice_' + $(this).val() + '" id="fitPrice_' + $(this).val() + '" class="form-control" style="width:60px;" value="售价" onfocus=goodsAdd.fitfocus(' + $(this).val() + '); onblur=goodsAdd.fitblur(' + $(this).val() + ');>';
						fitStr += '</div>';
					fitStr += '</td>';
				fitStr += '</tr>';
			})
			
			if (error_msg != '') {
				E.alert(error_msg);
				return false;
			}
			
			$('#fitSel table tbody').append(fitStr);
			
			$('.square-radio').iCheck({
	            checkboxClass: 'icheckbox_square-blue',
	            radioClass: 'iradio_square-blue',
	            increaseArea: '20%'
	        });
		},
		
		//配件可销售
		fitSale: function(flg){
			$('#fitPrice_' + flg).removeClass('hide');
		},
		
		//配件不可销售
		fitNoSale: function(flg){
			$('#fitPrice_' + flg).addClass('hide');
			$('#fitPrice_' + flg).val('售价');
		},
		
		fitDel: function(flg){
			$('#fit_' + flg).remove();
		},
		
		//获得焦点
		fitfocus: function(flg){
			var fitPrice = E.trim($('#fitPrice_' + flg).val());
			if (fitPrice == '售价') {
				$('#fitPrice_' + flg).val('');
			}
		},
		
		//失去焦点
		fitblur: function(flg){
			var fitPrice = E.trim($('#fitPrice_' + flg).val());
			if (fitPrice == '') {
				$('#fitPrice_' + flg).val('售价');
			} else if (!E.isNum(fitPrice) || fitPrice <= 0) {
				E.alert('请输入正确的配件售价');
				$('#fitPrice_' + flg).val('售价');
			}
		},
		
		fitCountBlur: function(flg){
			var checkCount = E.trim($('#fitCount_' + flg).val());
			if (!E.isInt(checkCount) || checkCount <= 0) {
				E.alert('请填写正确的配件数量');
				$('#fitCount_' + flg).val('1');
				return false;
			}
		},
		
		//切换配送间隔
		changeInter: function(){
			var interval = $('#interval').val();
			if (interval == 0) {
				$('#intervalTime').css('display', 'block');
				$('#cutTimeCase').css('display', 'none');
			} else if (interval == 1) {
				$('#intervalTime').css('display', 'none');
				$('#cutTimeCase').css('display', 'block');
			}
		},
		
		sameCount: 1,
		
		sameOrder: function(){
			var sameStr = '';
			sameStr += '<tr id=same_' + this.sameCount + '>';
				sameStr += '<td style="text-align:center;">';
					sameStr += '<a href="javascript:void(0);" onclick="goodsAdd.sameDel(' + this.sameCount + ');">删除</a>';
				sameStr += '</td>';
				sameStr += '<td>';
					sameStr += '<input id=sameOsTime_' + this.sameCount + ' name=sameOsTime_' + this.sameCount + ' class="form-control" type="text" style="width:118px;" value="" maxlength="20">';
				sameStr += '</td>';
				sameStr += '<td>';
					sameStr += '<input id=sameOeTime_' + this.sameCount + ' name=sameOeTime_' + this.sameCount + ' class="form-control" type="text" style="width:118px;" value="" maxlength="20">';
				sameStr += '</td>';
				sameStr += '<td>';
					sameStr += '<input id=sameDsTime_' + this.sameCount + ' name=sameDsTime_' + this.sameCount + ' class="form-control" type="text" style="width:118px;" value="" maxlength="20">';
				sameStr += '</td>';
				sameStr += '<td>';
					sameStr += '<input id=sameDeTime_' + this.sameCount + ' name=sameDeTime_' + this.sameCount + ' class="form-control" type="text" style="width:118px;" value="" maxlength="20">';
				sameStr += '</td>';
			sameStr += '</tr>';
			
			this.sameCount++;

			$('#intervalTime table tbody').append(sameStr);
		},
		
		sameDel: function(flg){
			$('#same_' + flg).remove();
		},
		
		//保存检查
		check: function(){
			editor.sync();
			var error_msg = '';
			this.dt = E.getFormValues('addForm');

			//主商品
			if (this.dt.setMainGoods != 0 && this.dt.setMainGoods != 1) {
				error_msg += '请设置主商品<br/>';
			}

			//sku
			if (this.dt.product_code == '') {
				error_msg += '请填写商品SKU<br/>';
			}
			
			//售价
			if (!E.isNum(this.dt.salePrice) || this.dt.salePrice <= 0) {
				error_msg += '请填写正确的商品售价<br/>';
			}
			
			//提前预定时间
			if (this.dt.aheadTime == 0) {
				error_msg += '请选择提前预定时间<br/>';
			} else {
				this.dt.aheadTimeText = $('#aheadTime option:checked').text();
			}
			
			//食用
			if (this.dt.edible != 0) {
				this.dt.edibleText = $('#edible option:checked').text();
			} else {
				this.dt.edibleText = '';
			}
			
			//尺寸
			if (this.dt.size != 0) {
				this.dt.sizeText = $('#size option:checked').text();
			} else {
				this.dt.sizeText = '';
			}
			
			//切分
			var syncopate = [];
			$('#selSyncopate option').each(function(k, v){
				var synV = $(this).val();
				var synT = $(this).text();
				syncopate.push([synV, synT]);
			});
			this.dt.syncopate = syncopate;
			
			//生日牌
			var birthcard = [];
			$('#selBirthcard option').each(function(k, v){
				var birthV = $(this).val();
				var birthT = $(this).text();
				birthcard.push([birthV, birthT]);
			});
			this.dt.birthcard = birthcard;

			//网站状态
			if (this.dt.useFlg == 0) {
				error_msg += '请选择网站状态<br/>';
			}
			
			//销售状态
			if (this.dt.forsale == 0) {
				error_msg += '请选择销售状态<br/>';
			}
			
			//试吃状态
			if (this.dt.foretaste == 0) {
				error_msg += '请选择试吃状态<br/>';
			}
			
			//配件
			/*
			var fitLen = $('#fitSel table tbody tr').length;
			if (fitLen <= 0) {
				error_msg += '请选择商品配件<br/>';
			} else {
				$('#fitSel table tbody tr').each(function(k, v){
					var fidArray = $(this).attr('id').split('_');
					var isSale = $('[name=sale_radio_' + fidArray[1] + ']').val();

					if (isSale == 1) {
						var fitPrice = $(this).find('[name^=fitPrice_]').val();
						if (E.isNum(fitPrice) || fitPrice <= 0) {
							E.alert('请填写正确的配件售价');
							return false;
						}
					}

				});
			}
			*/
			
			//配送时间控制
			if (this.dt.startDeliver == '') {
				error_msg += '请填写起始配送时间<br/>';
			} else if (this.dt.startDeliver.length != 8) {
				error_msg += '请填写正确的起始配送时间<br/>';
			}
			
			//结束配送时间
			if (this.dt.endDeliver == '') {
				error_msg += '请填写结束配送时间<br/>';
			} else if (this.dt.endDeliver.length != 8) {
				error_msg += '请填写正确的结束配送时间<br/>';
			}
			
			//配送间隔
			if (this.dt.interval != 0 && this.dt.interval != 1) {
				error_msg += '请选择配送间隔<br/>';
			} else {
				if (this.dt.interval == 0) {
					var iLen = $('#intervalTime table tbody tr').length;
					if (iLen <= 0) {
						error_msg += '请维护“当天下单/配送时间控制”数据<br/>';
					}
					
					var eachMsg = '';
					$('[name*=sameOsTime_]').each(function(k, v){
						var OsTime = E.trim($(this).val());
						if (OsTime == '' || OsTime.length != 8) {
							eachMsg = '请维护正确的“当天下单/配送时间控制”数据';
						}
					});
					if (eachMsg != '') {
						E.alert(eachMsg);
						return false;
					}
					$('[name*=sameOeTime_]').each(function(k, v){
						var OeTime = E.trim($(this).val());
						if (OeTime == '' || OeTime.length != 8) {
							eachMsg = '请维护正确的“当天下单/配送时间控制”数据';
						}
					});
					if (eachMsg != '') {
						E.alert(eachMsg);
						return false;
					}
					$('[name*=sameDsTime_]').each(function(k, v){
						var DsTime = E.trim($(this).val());
						if (DsTime == '' || DsTime.length != 8) {
							eachMsg = '请维护正确的“当天下单/配送时间控制”数据';
						}
					});
					if (eachMsg != '') {
						E.alert(eachMsg);
						return false;
					}
					$('[name*=sameDeTime_]').each(function(k, v){
						var DeTime = E.trim($(this).val());
						if (DeTime == '' || DeTime.length != 8) {
							eachMsg = '请维护正确的“当天下单/配送时间控制”数据';
						}
					});
					if (eachMsg != '') {
						E.alert(eachMsg);
						return false;
					}
					
				} else if (this.dt.interval == 1 && this.dt.cutTime == '') {
					error_msg += '请填写截单时间<br/>'
				} else if (this.dt.interval == 1 && this.dt.cutTime.length != 8) {
					error_msg += '请填写正确的截单时间<br/>'
				}
			}
			this.dt.sameCount = this.sameCount;
			
			if (error_msg != '') {
				E.alert(error_msg);
			} else {
				E.confirm('您确认添加此SKU吗？', 'goodsAdd.save');
			}
		},
		
		//ajax保存
		save: function(){
			E.loadding.open();
			E.ajax_post({
				url : '/invokingAjax-backend/goods/goodsAdd.ajax?operFlg=4',
				data: {
					params: goodsAdd.dt
				},
				call: 'goodsAdd.saveCall'
			});
		},
		
		//添加商品后返回刷新页面
		saveCall: function(o){
			E.loadding.close();
			if (o.code == 200) {
				//E.alert(o.message, 2, 'E.refresh');
				E.alert(o.message, 2);
				E.popup.close();
				
				var operate = '';
				operate += '<a onclick="goodsAdd.editSku(' + o.data.specGroupID + ', ' + o.data.specID + ');" href="javascript:void(0);">编辑</a>';
				operate += '<input type="hidden" name=tPostID_' + o.data.specGroupID + '_' + o.data.specID + ' id=tPostID_' + o.data.specGroupID + '_' + o.data.specID + ' value=' + o.data.tPostID + '>';

				$('#operate_' + o.data.specGroupID + '_' + o.data.specID).html(operate);
				$('#sku_' + o.data.specGroupID + '_' + o.data.specID).html(o.data.product_code);
				$('#useFlg_' + o.data.specGroupID + '_' + o.data.specID).html(o.data.useFlg);
				$('#forsale_' + o.data.specGroupID + '_' + o.data.specID).html(o.data.forsale);
				$('#foretaste_' + o.data.specGroupID + '_' + o.data.specID).html(o.data.foretaste);
				$('#schedule_' + o.data.specGroupID + '_' + o.data.specID).html(o.data.aheadTime);
				$('#salePrice_' + o.data.specGroupID + '_' + o.data.specID).html(parseFloat(o.data.salePrice).toFixed(2));

			} else {
				E.alert(o.message);
			}
		}
	}
</script>